23. Adding Data to a Vector
Adding Data to a Vector
In the previous exercises, you have declared and initialized vectors, and you have also accessed vector elements. In order to make full use of vectors in your code though, you will need to be able to add additional elements to them. Have a look at the following notebook for examples of how to do this.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: jupyter
- Opened files (when workspace is loaded): n/a
On to an Exercise
In this notebook and the last, you learned about two useful tools:
- String streams, and
vector
push_back
.
The string streaming objects in C++ are very powerful, and there are are many more ways that an istringstream
can be used. We encourage you to have a look at all of the available functions in the C++ reference. However, at this point you are ready for the next exercise. In the next exercise, you will parse string lines from the board and store the int
s in a vector using an istringstream
object and the push_back
method. Have a careful look a the previous examples again, and copy paste any code you think you might need before clicking the Next
button below.